<template>
    <el-dialog width="600" :title="$t('Order.fillInTheLogisticsNumber')" v-model="visible" :close-on-click-modal="false"
        @close="closeDia" draggable>
        <el-form ref="dataFormRef" :model="form" :rules="dataRules" formDialogRef label-width="90px" v-loading="loading">
            <el-form-item prop="logisticsNo" :label="$t('Order.logisticsNo')">
                <el-input v-model="form.logisticsNo" :placeholder="$t('Order.fillInTheLogisticsNumber')" clearable
                    show-word-limit :maxlength="100" />
            </el-form-item>
        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="visible = false">{{ $t('common.cancelButtonText') }}</el-button>
                <el-button @click="onSubmit" type="primary" :disabled="loading">{{ $t('common.confirmButtonText')
                }}</el-button>
            </span>
        </template>
    </el-dialog>
</template>
<script setup lang="ts">
import { orderdeliveryAPI } from '/@/api/bizs/Order';

import { useMessage, useMessageBox} from "/@/hooks/message";
// 定义i18n
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
const loading = ref(false)
const visible = ref(false)
const dataFormRef = ref()
const props = defineProps(["getDataList"])
const form = reactive({
    logisticsNo: "",
    deliveryType:1
})
const dataRules = ref({

})


const orderId =ref("")

const closeDia = () => {
    nextTick(() => {
        dataFormRef.value?.resetFields();
    });
}

const onSubmit = async () => {


    try {	
		await useMessageBox().confirm(t('Order.confirmDelivertText'));
	} catch {
		return;
	}

    try {
        loading.value = true;
        // 请求api
        await orderdeliveryAPI(orderId.value,form)
		useMessage().success(t('Order.successfulOperation'));
        visible.value = false;
        props.getDataList()
    } catch (err: any) {
        useMessage().error(err.msg);
    } finally {
        loading.value = false;

    }

}


defineExpose({
    orderId,
    visible,
})
</script>